import request from '@/config/axios'
import { PageData } from '@/api/common/types'
import { SystemRole, SystemRoleQuery, SystemRoleStatusUpdate } from '@/api/system/role/types'
import { SystemRoleAssignMenus } from '@/api/system/role/types'

export const getSystemRoleListApi = (
  params: SystemRoleQuery
): Promise<IResponse<PageData<SystemRole>>> => {
  return request.get({ url: '/system/role/list', params })
}

export const checkRoleNameApi = (params) => {
  return request.get({ url: '/system/role/name/check', params })
}

export const createSystemRoleApi = (data: SystemRole): Promise<IResponse<SystemRole>> => {
  return request.post({ url: '/system/role/add', data })
}

export const updateSystemRoleApi = (data: SystemRole): Promise<IResponse<SystemRole>> => {
  return request.post({ url: '/system/role/update', data })
}

export const assignMenusApi = (data: SystemRoleAssignMenus) => {
  return request.post({ url: '/system/role/assign/menus', data })
}

export const getDeleteSystemRoleApi = (roleId: string) => {
  return request.post({ url: '/system/role/delete', params: { roleId: roleId } })
}

export const getUpdateRoleStatusApi = (data: SystemRoleStatusUpdate) => {
  return request.post({ url: '/system/role/update/status', data })
}
